<?php

namespace App\Http\Controllers\Admin\Member;

use App\Http\Controllers\Controller;

use App\Models\MemberCard;
use App\Traits\Controllers\AdminTraits;
use App\Traits\Controllers\UpdateStatusTraits;
use App\Transformers\Member\MemberCardTransFormer;
use Illuminate\Http\Request;

class MemberCardController extends Controller
{
    /**
     * 会员卡表 增删改查
     */
   use AdminTraits;
   use UpdateStatusTraits;

   public $model = MemberCard::class;

   public $transformer = MemberCardTransFormer::class;

   /**
    * 改变状态
    */
   public function memberCardStatus(MemberCard $status){
       $status->status =$status->status == 1 ? 0 : 1;
       $status->save();
       return $this->response->noContent();

   }
    /**
     * 参数验证规则
     *
     * @param Request $request
     * @return array
     */
    public function rules(Request $request): array
    {
        switch ($request->method()) {
            case 'GET':
                return [];
                break;
            case 'POST':
            case 'PUT':
            case 'PATCH':
                return [
                    'card_batch_id'=>'required|exists:member_card_batches,id',
                    'user_id'=>'required|exists:users,id',
                    'card_number'=>'required|max:32',
                    'card_password'=>'required|max:32',
                    'use_time'=>'required',

                ];
                break;

        }
        return [];
    }

    /**
     * 验证信息
     *
     * @return array
     */
    public function ruleMessages(): array
    {
        return [
            'card_batch_id.required'=>'批次名称 不能为空',
            'card_batch_id.exists'=>'批次号不存在',
            'user_id.required'=>'用户名不能为空',
            'user_id.exists'=>'用户名不存在',
            'card_password.required'=>'密码不能为空',
            'card_password.max'=>'密码不能超过32字符',
            'use_time.required'=>'使用时间不能为空',
            'card_number.required'=>'卡号不能为空',
            'card_number.max'=>'卡号不能超过32字符',
     ];
    }

}
